package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.KnowledgesportDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.KnowledgeSport;
import com.itheima.service.KnowledgesportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = KnowledgesportService.class)
@Transactional
public class KnowledgesportServiceImpl implements KnowledgesportService {
    @Autowired
    private KnowledgesportDao knowledgesportDao;
    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize =queryPageBean.getPageSize();
        String queryString =queryPageBean.getQueryString();

        PageHelper.startPage(currentPage,pageSize);
        Page<KnowledgeSport> page = knowledgesportDao.selectByCondition(queryString);

        long total = page.getTotal();
        List<KnowledgeSport> rows = page.getResult();

        return new PageResult(total,rows);
    }

    @Override
    public void add(KnowledgeSport knowledgeSport) {
        knowledgesportDao.add(knowledgeSport);
    }
    @Override
    public void deleteById(Integer id) {

        knowledgesportDao.deleteById(id);
    }
    @Override
    public void edit(KnowledgeSport knowledgeSport) {
        knowledgesportDao.edit(knowledgeSport);
    }

    @Override
    public KnowledgeSport findById(Integer id) {
        return knowledgesportDao.findById(id);
    }


}
